home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_weap_ailightning.cog < prev    next >
Text File  |  1999-11-15  |  6KB  |  185 lines

  1. # Jones 3D Cog Script
  2. #
  3. # weap_AILightning.cog
  4. #
  5. # Generic Weapon Class Cog for AI lightning fire.
  6. #
  7. # [MDR]
  8. #
  9. # (C) 1999 LucasArts Entertainment Company LLC. All Rights Reserved
  10. #
  11. # ===================================================================
  12.  
  13. symbols
  14.  
  15. message        fire
  16. message        timer
  17. message        touched
  18. message        removed
  19.  
  20. # ************************** SUBROUTINES ********************
  21. flex        CreateNewArc                                local
  22.  
  23. # ************************* TEMPLATES ***************************
  24. template    tpl_ghost=ghost                                local
  25. template    tpl_hit=+shortElecHit                        local
  26.  
  27. material    mat_arc0=aet_4sfx_lightning_v2_a.mat        local
  28. material    mat_arc1=aet_4sfx_lightning_v2_b.mat        local
  29. material    mat_arc2=aet_4sfx_lightning_v2_c.mat        local
  30. material    mat_arc3=aet_4sfx_lightning_v2_d.mat        local
  31. material    mat_arc4=aet_4sfx_lightning_v2_e.mat        local
  32.  
  33. # ************************* MISC LOCAL VARS *********************
  34. thing        t_shooter                                    local
  35. thing        t_victim                                    local
  36. thing        t_bullet                                    local
  37. thing        t_arc                                        local
  38. thing        t_arcSource                                    local
  39. thing        t_arcTarget                                    local
  40. thing        t_arcHit                                    local
  41. flex        f_arcSize                                    local
  42. flex        f_arcTime=0.05                                local
  43. vector        vec_pos                                        local
  44.  
  45. end
  46.  
  47.  
  48. # ===================================================================
  49. code
  50.  
  51. # ...................................................................
  52. # Handler for FIRE msg (the one sent from weapon module)
  53. # ...................................................................
  54. fire:
  55.  
  56.     t_bullet    = GetSenderRef();
  57.     t_shooter    = GetSourceRef();
  58.     if ( (t_bullet < 0) || (t_shooter < 0) )
  59.         return;                                                            # Bad bullet?  Bail...
  60.  
  61.     f_arcSize    = GetThingMoveSize(t_bullet);                            # Beam size is size of bullet
  62.  
  63.     vec_pos        = VectorAdd( GetThingPos(t_shooter), VectorTransformToOrient(t_shooter, GetThingFireoffset(t_shooter)) );
  64.     t_arcSource = CreateThingAtPos(tpl_ghost, GetThingSector(t_shooter), vec_pos, '0 0 0');
  65.     if ( t_arcSource < 0 )
  66.         return;
  67.  
  68.     CaptureThing(t_arcSource);                                            # Enable arcSource feedback
  69.     AttachThingToThingEx(t_arcSource, t_shooter, 0x08);                    # Attach arcSource to bullet
  70.     SetLifeLeft(t_arcSource, GetLifeLeft(t_bullet));                    # Set max arcing time
  71.     SetLifeLeft(t_bullet, 0);                                            # Reset the bullet back to "immortal"
  72.  
  73.     SetThingUserData(t_bullet, t_arcSource);                            # bullet remembers arcSource
  74.     SetThingUserData(t_arcSource, t_bullet);                            # arcSource remembers bullet
  75.  
  76.     call CreateNewArc;                                                    # Create first arc
  77.  
  78.     PlaySoundClass(t_bullet, 106);                                        # Play a SITHSOUNDCLASS_FIRE1 sound on bullet
  79.  
  80. #    DEBUGFLEX(t_arcSource, "Made new arcSource =");
  81.     return;
  82.  
  83.  
  84. # ...................................................................
  85. timer:
  86.  
  87.     t_arcSource = GetSenderRef();
  88.     if ( (t_arcSource < 0) || (GetThingType(t_arcSource) != 8) )        # Check for SITH_THING_GHOST
  89.         return;
  90.  
  91.     call CreateNewArc;                                                    # Make a new arc
  92.  
  93. #    DEBUGFLEX(t_arcSource, "Timer for arcSource =");
  94.     return;
  95.  
  96.  
  97. # ...................................................................
  98. # Bullet hit someTHING
  99. # ...................................................................
  100. touched:
  101.     t_bullet = GetSenderRef();
  102.     if ( (t_bullet < 0) || (GetThingType(t_bullet) != 3) )                # Check for SITH_THING_WEAPON
  103.         return;
  104.  
  105.     t_arcSource = GetThingUserData(t_bullet);
  106.     if ( GetThingType(t_arcSource) != 8 )                                # Check for SITH_THING_GHOST
  107.         return;
  108.  
  109.     t_victim    = GetSourceRef();
  110.     SetThingUserData(t_arcSource, t_victim);                            # arcSource now hits victim
  111.     SetThingUserData(t_bullet, 0);                                        # bullet forgets arcSource
  112.  
  113.     # Create hit sprite
  114.     vec_pos = VectorSet( 0, 0, VectorZ(GetThingEyeOffset(t_victim))/2 );
  115.     vec_pos = VectorAdd(GetThingPos(t_victim), vec_pos);
  116.  
  117.     t_arcHit = CreateThingAtPos(tpl_hit, FindNewSectorFromThing(t_victim, vec_pos), vec_pos, '0 0 0');
  118.     if (t_arcHit > -1)
  119.     {
  120.         AttachThingToThingEx(t_arcHit, t_victim, 0x08);                    # Attach hit sprite to victim
  121.     }
  122.  
  123. #    DEBUGFLEX(t_arcSource, "Bullet TOUCHED, attaching arc to victim.  arcSource =");
  124.     return;
  125.  
  126.  
  127. # ...................................................................
  128. # Bullet has collided
  129. # ...................................................................
  130. removed:
  131.  
  132.     t_bullet = GetSenderRef();                                            # bullet or arcSource?
  133.  
  134.     if ( GetThingType(t_bullet) == 3 )                                    # Check for SITH_THING_WEAPON (bullet)
  135.     {
  136.         t_arcSource = GetThingUserData(t_bullet);
  137.         if ( t_arcSource == 0 )                                            # No arcSource referenced?
  138.             return;
  139.  
  140.         if ( GetThingType(t_arcSource) == 8 )                            # Check for SITH_THING_GHOST
  141.         {
  142. #            DEBUGPRINT("Bullet removed, creating temp arcTarget");
  143.  
  144.             t_arcTarget = CreateThingAtPos(tpl_ghost, GetThingSector(t_bullet), GetThingPos(t_bullet), '0 0 0');
  145.             if ( t_arcTarget > 0 )
  146.             {
  147.                 SetThingUserData(t_arcSource, t_arcTarget);
  148.                 SetLifeLeft(t_arcTarget, GetLifeLeft(t_arcSource));
  149.             }
  150.         }
  151.     }
  152.  
  153.     if ( GetThingType(t_bullet) == 8 )                                    # Check for SITH_THING_GHOST (arcSource)
  154.     {
  155.         SetThingTimer(t_bullet ,0);
  156.     }
  157.  
  158.     return;
  159.  
  160.  
  161. # ===================================================================
  162. #    Subroutines
  163. # ===================================================================
  164.  
  165. # ...................................................................
  166. # t_arcSource MUST be initialized before this call!
  167. # ...................................................................
  168. CreateNewArc:
  169.  
  170.     t_arcTarget    = GetThingUserData(t_arcSource);
  171.  
  172.     vec_pos = VectorSet( 0, 0, VectorZ(GetThingEyeOffset(t_arcTarget))/2 );
  173.     vec_pos = VectorAdd(GetThingPos(t_arcTarget), vec_pos);
  174.  
  175. #    t_arc = CreatePolylineThing(t_arcSource, t_arcTarget, '0 0 0', mat_arc0[RandBetween(0, 4)], f_arcSize, f_arcSize, f_arcTime);
  176.     t_arc = CreatePolylineThing(t_arcSource, -1, vec_pos, mat_arc0[RandBetween(0, 4)], f_arcSize, f_arcSize, f_arcTime);
  177.  
  178.     SetThingTimer(t_arcSource, f_arcTime);                                # Set next arc time
  179.  
  180.     return;
  181.  
  182.  
  183. # ===================================================================
  184. end
  185.